package myboot.myblog.controller.admin;

import myboot.myblog.service.ConfigurationService;
import myboot.myblog.utils.Result;
import myboot.myblog.utils.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author hujh
 */
@RestController
@RequestMapping("/admin")
public class ConfigurationController {

    @Autowired
    private ConfigurationService configurationService;

    /**
     * 修改站点信息
     */
    @PostMapping("/configurations/website")
    public Result updateWebsite(@RequestParam Map<String,String> params){
        int rows = configurationService.updateWebsite(params);
        if (rows == params.size()) {
            return ResultGenerator.getSuccessResult(rows);
        }else {
            return ResultGenerator.getFailResult("修改失败!");
        }
    }

    /**
     * 修改个人信息
     */
    @PostMapping("/configurations/userInfo")
    public Result updateUserInfo(@RequestParam Map<String,String> params){
        int rows = configurationService.updateUserInfo(params);
        if (rows == params.size()) {
            return ResultGenerator.getSuccessResult(rows);
        }else {
            return ResultGenerator.getFailResult("修改失败!");
        }
    }

    /**
     * 修改底部设置
     */
    @PostMapping("/configurations/footer")
    public Result updateFooter(@RequestParam Map<String,String> params){
        int rows = configurationService.updateFooter(params);
        if (rows == params.size()) {
            return ResultGenerator.getSuccessResult(rows);
        }else {
            return ResultGenerator.getFailResult("修改失败!");
        }
    }

}
